package com.cyj.dream.core.constant.pagemodel;

import com.cyj.dream.core.constant.enums.ResultCode;

/**
 * @Description: 封装响应返回类型
 * @BelongsProject: DreamChardonnay
 * @BelongsPackage: com.cyj.dream.core.constant.pagemodel
 * @Author: ChenYongJia
 * @CreateTime: 2021-09-26 10:30
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
public class ResponseUtil {

    public static <T> Response<T> success() {
        return success(null, ResultCode.SUCCESS.message());
    }

    public static <T> Response<T> success(String message) {
        return success(null, message);
    }

    public static <T> Response<T> success(T data) {
        return success(data, ResultCode.SUCCESS.message());
    }

    public static <T> Response<T> success(T data, String message) {
        Response<T> response = new Response<>();
        response.setCode(ResultCode.SUCCESS.code());
        response.setMessage(message);
        response.setData(data);
        return response;
    }

    public static Response<Void> error() {
        return error(ResultCode.ERROR.code(), ResultCode.ERROR.message());
    }

    public static Response<Void> error(String errMsg) {
        return error(ResultCode.ERROR.code(), errMsg);
    }

    public static Response<Void> error(int errCode, String errMsg) {
        Response<Void> response = new Response<>();
        response.setCode(errCode);
        response.setMessage(errMsg);
        return response;
    }

    public static <T> Response<T> errorObject(int errCode, String errMsg) {
        Response<T> response = new Response<>();
        response.setCode(errCode);
        response.setMessage(errMsg);
        return response;
    }
}
